@extends('admin.layout.index')
@section('content')
<div class="portlet box blue">

		<div class="portlet-title">

			<div class="caption"><i class="icon-reorder"></i>用户添加</div>

			<div class="tools">

				<a href="javascript:;" class="reload"></a>


			</div>

		</div>

		<div class="portlet-body form">


			<!-- BEGIN FORM-->

			<form action="/admin/user" class="form-horizontal" method="post">
				{{ csrf_field() }}

				<div class="control-group warning">

					<label class="control-label" for="inputWarning">用户名</label>

					<div class="controls">

						<input type="text" class="span6 m-wrap" id="username" name="username">

						<span class="help-inline" id='userSpan'></span>

					</div>

				</div>
				<div class="control-group warning">

					<label class="control-label" for="inputWarning">密码</label>

					<div class="controls">

						<input type="password" class="span6 m-wrap" id="password" name="password">

						<span class="help-inline" id='passSpan'></span>

					</div>

				</div>
				<div class="control-group warning">

					<label class="control-label" for="inputWarning">确认密码</label>

					<div class="controls">

						<input type="password" class="span6 m-wrap" id="repassword" name="repassword">

						<span class="help-inline" id="repassSpan"></span>

					</div>

				</div>
				
				
				<div class="form-actions">

					<input type="submit" class="btn blue" id="submit" value="添加">
					<button type="reset" class="btn">重置</button>

				</div>
				
				<script>
						var preg1 = /^[a-z0-9_A-Z]{5,12}$/
						var preg2 = /^[\S]{6,18}$/
					$('#username').focus(function(){
						$('#userSpan').html('请输入5-12位');
					}).blur(function(){
						var username = $(this).val()
						$.get('/admin/ver?username='+username,function(msg){
							if(msg==1){
								$('#userSpan').html('用户名已存在');
							}
						})
						if (preg1.exec($(this).val())){
							$('#userSpan').html('✔');
						}else{
							$('#userSpan').html('请输入正确的用户名');
						}
					})
					$('#password').focus(function(){
						$('#passSpan').html('请输入6-18位');
					}).blur(function(){
						if (!preg2.exec($(this).val())){
							$('#passSpan').html('请输入正确的密码');
						}else{
							$('#passSpan').html('✔');
						}
					})
					$('#repassword').focus(function(){
						$('#repassSpan').html('请输入相同密码');
					}).blur(function(){
						if ($(this).val() != $('#password').val() ){
							$('#repassSpan').html('请输入正确的密码');
						}else{
							$('#repassSpan').html('✔');
						}
					})
					$('#submit').click(function(){
						if(!(preg1.exec($('#username').val()) && preg2.exec($('#password').val()) && $('#password').val() == $('#password').val())){
							return false;
						}
						if ($('#userSpan').html() == '用户名已存在') {return false;};
					})
					
				</script>

			</form>

			<!-- END FORM-->

		</div>

	</div>
@endsection